<template>
  <div class="dialog-demo-page">
    <div class="demo-header">
      <h1>🍊 橘子小说弹窗演示</h1>
      <p>体验全新的炫酷弹窗和Toast提示效果</p>
    </div>

    <div class="demo-section">
      <h2>Toast 提示框</h2>
      <div class="demo-buttons">
        <button class="demo-btn success" @click="showSuccessToast">
          <span class="btn-icon">✅</span>
          成功提示
        </button>
        <button class="demo-btn error" @click="showErrorToast">
          <span class="btn-icon">❌</span>
          错误提示
        </button>
        <button class="demo-btn warning" @click="showWarningToast">
          <span class="btn-icon">⚠️</span>
          警告提示
        </button>
        <button class="demo-btn info" @click="showInfoToast">
          <span class="btn-icon">ℹ️</span>
          信息提示
        </button>
      </div>
    </div>

    <div class="demo-section">
      <h2>弹窗对话框</h2>
      <div class="demo-buttons">
        <button class="demo-btn primary" @click="showSimpleDialog">
          <span class="btn-icon">💬</span>
          简单弹窗
        </button>
        <button class="demo-btn primary" @click="showConfirmDialog">
          <span class="btn-icon">❓</span>
          确认弹窗
        </button>
        <button class="demo-btn primary" @click="showVipDialog">
          <span class="btn-icon">👑</span>
          VIP弹窗
        </button>
        <button class="demo-btn primary" @click="showPaymentDialog">
          <span class="btn-icon">💳</span>
          支付弹窗
        </button>
      </div>
    </div>

    <!-- 简单弹窗 -->
    <div v-if="simpleDialogVisible" class="dialog-overlay" @click="simpleDialogVisible = false">
      <div class="dialog" @click.stop>
        <div class="dialog-header">
          <h3>🎉 欢迎使用橘子小说</h3>
          <button class="close-btn" @click="simpleDialogVisible = false">
            <svg viewBox="0 0 24 24" fill="currentColor">
              <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
            </svg>
          </button>
        </div>
        <div class="dialog-content">
          <p>这是一个使用新样式的简单弹窗，具有炫酷的动画效果和橘子主题设计。</p>
          <p>✨ 特点：</p>
          <ul>
            <li>🎨 橘子色主题渐变</li>
            <li>💫 流畅的动画效果</li>
            <li>📱 完美的移动端适配</li>
            <li>🌙 深色模式支持</li>
          </ul>
        </div>
        <div class="dialog-footer">
          <button class="btn secondary" @click="simpleDialogVisible = false">关闭</button>
          <button class="btn primary" @click="handleSimpleAction">了解更多</button>
        </div>
      </div>
    </div>

    <!-- VIP弹窗 -->
    <div v-if="vipDialogVisible" class="dialog-overlay" @click="vipDialogVisible = false">
      <div class="dialog vip-dialog large" @click.stop>
        <div class="dialog-header">
          <h3>👑 开通VIP会员</h3>
          <button class="close-btn" @click="vipDialogVisible = false">
            <svg viewBox="0 0 24 24" fill="currentColor">
              <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
            </svg>
          </button>
        </div>
        <div class="dialog-content">
          <div class="vip-packages">
            <div class="vip-package" @click="selectVipPackage('monthly')">
              <h4>月度VIP</h4>
              <div class="price">¥15/月</div>
              <div class="benefits">
                <p>• 免费阅读VIP章节</p>
                <p>• 无广告阅读体验</p>
                <p>• 专属VIP标识</p>
              </div>
            </div>
            <div class="vip-package popular" @click="selectVipPackage('yearly')">
              <div class="popular-badge">最受欢迎</div>
              <h4>年度VIP</h4>
              <div class="price">¥150/年</div>
              <div class="original-price">原价 ¥180</div>
              <div class="benefits">
                <p>• 月度VIP所有特权</p>
                <p>• 每月赠送100书币</p>
                <p>• 专属客服支持</p>
                <p>• 提前阅读新书</p>
              </div>
            </div>
          </div>
        </div>
        <div class="dialog-footer">
          <button class="btn secondary" @click="vipDialogVisible = false">取消</button>
          <button class="btn primary" @click="handleVipPurchase">立即开通</button>
        </div>
      </div>
    </div>

    <!-- 支付弹窗 -->
    <div v-if="paymentDialogVisible" class="dialog-overlay" @click="paymentDialogVisible = false">
      <div class="payment-dialog" @click.stop>
        <div class="payment-header">
          <div class="chapter-info">
            <h3>第一章 - 橘子小说的诞生</h3>
            <div class="price-info">
              <span class="price">5</span>
              <span class="currency">书币</span>
            </div>
          </div>
          <button class="close-btn" @click="paymentDialogVisible = false">
            <svg viewBox="0 0 24 24" fill="currentColor">
              <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
            </svg>
          </button>
        </div>
        <div class="dialog-content">
          <p>解锁本章节需要消耗 5 书币，您当前余额：<strong>100 书币</strong></p>
          <div class="payment-options">
            <div class="option">
              <input type="radio" id="coins" name="payment" checked>
              <label for="coins">使用书币支付</label>
            </div>
            <div class="option">
              <input type="radio" id="vip" name="payment">
              <label for="vip">VIP免费阅读</label>
            </div>
          </div>
        </div>
        <div class="dialog-footer">
          <button class="btn secondary" @click="paymentDialogVisible = false">取消</button>
          <button class="btn primary" @click="handlePayment">确认支付</button>
        </div>
      </div>
    </div>

    <!-- 确认弹窗组件 -->
    <ConfirmDialog
      v-model:visible="confirmDialogVisible"
      title="删除确认"
      message="您确定要删除这本小说吗？此操作不可撤销。"
      type="warning"
      @confirm="handleConfirm"
      @cancel="handleCancel"
    />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { showToast } from '@/utils/toast'
import ConfirmDialog from '@/components/ConfirmDialog.vue'

// 弹窗状态
const simpleDialogVisible = ref(false)
const vipDialogVisible = ref(false)
const paymentDialogVisible = ref(false)
const confirmDialogVisible = ref(false)

// Toast 示例
const showSuccessToast = () => {
  showToast.success('操作成功！数据已保存', '成功')
}

const showErrorToast = () => {
  showToast.error('网络连接失败，请检查网络设置', '错误')
}

const showWarningToast = () => {
  showToast.warning('您的VIP即将过期，请及时续费', '提醒')
}

const showInfoToast = () => {
  showToast.info('新版本已发布，快去体验新功能吧！', '通知')
}

// 弹窗操作
const showSimpleDialog = () => {
  simpleDialogVisible.value = true
}

const showConfirmDialog = () => {
  confirmDialogVisible.value = true
}

const showVipDialog = () => {
  vipDialogVisible.value = true
}

const showPaymentDialog = () => {
  paymentDialogVisible.value = true
}

const handleSimpleAction = () => {
  showToast.success('感谢您的关注！', '谢谢')
  simpleDialogVisible.value = false
}

const selectVipPackage = (type: string) => {
  showToast.info(`您选择了${type === 'monthly' ? '月度' : '年度'}VIP套餐`)
}

const handleVipPurchase = () => {
  showToast.success('VIP开通成功！享受专属特权吧', '恭喜')
  vipDialogVisible.value = false
}

const handlePayment = () => {
  showToast.success('支付成功！章节已解锁', '支付成功')
  paymentDialogVisible.value = false
}

const handleConfirm = () => {
  showToast.success('小说已删除', '删除成功')
  confirmDialogVisible.value = false
}

const handleCancel = () => {
  showToast.info('已取消删除操作')
}
</script>

<style scoped>
.dialog-demo-page {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
  min-height: 100vh;
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.05), rgba(255, 165, 0, 0.02));
}

.demo-header {
  text-align: center;
  margin-bottom: 40px;
  
  h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
  }
  
  p {
    color: #666;
    font-size: 1.1rem;
  }
}

.demo-section {
  margin-bottom: 40px;
  
  h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(255, 107, 53, 0.2);
  }
}

.demo-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.demo-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 24px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  
  &::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transition: all 0.3s ease;
    transform: translate(-50%, -50%);
  }
  
  &:hover::before {
    width: 200px;
    height: 200px;
  }
  
  &:active {
    transform: scale(0.95);
  }
  
  .btn-icon {
    font-size: 18px;
  }
  
  &.success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
    }
  }
  
  &.error {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
    }
  }
  
  &.warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
    }
  }
  
  &.info {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
    }
  }
  
  &.primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 15px rgba(255, 107, 53, 0.3);
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(255, 107, 53, 0.4);
    }
  }
}

.payment-options {
  margin: 20px 0;
  
  .option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    
    input[type="radio"] {
      accent-color: var(--primary-color);
    }
    
    label {
      font-size: 14px;
      color: #333;
      cursor: pointer;
    }
  }
}

@media (max-width: 768px) {
  .dialog-demo-page {
    padding: 16px;
  }
  
  .demo-header h1 {
    font-size: 2rem;
  }
  
  .demo-buttons {
    grid-template-columns: 1fr;
  }
}
</style> 